package com.bookocean.infrastructure.persistence.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bookocean.infrastructure.persistence.po.NovelParticipantPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 小说参与者 Mapper 接口
 * 
 * @author BookOcean
 * @since 2024-01-01
 */
@Mapper
public interface NovelParticipantMapper extends BaseMapper<NovelParticipantPO> {

    /**
     * 获取轮到写作的用户ID（简化实现：按参与顺序轮流）
     * 
     * @param novelId 小说ID
     * @return 用户ID
     */
    @Select("SELECT user_id FROM novel_participant_po " +
            "WHERE novel_id = #{novelId} AND status = 1 " +
            "ORDER BY participant_order LIMIT 1")
    Long getNextWriterUserId(@Param("novelId") Long novelId);
}
